package org.jeecg.modules.system.util;


import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.jeecg.modules.system.entity.CustomerReport;

import java.util.HashMap;
import cn.hutool.http.HttpUtil;
/**
 * <P>
 * 对应部门的表,处理并查找树级数据
 * <P>
 *
 * @Author: Steve
 * @Date: 2019-01-22
 */
public class MapUtil {


    /**
     * 获取 DepartIdModel
     * @return
     */
    public static CustomerReport getCustomerReport(CustomerReport customerReport) {
        try {
            HashMap<String, Object> paramMap = new HashMap<>();

            paramMap.put("address", customerReport.getAddressType());
            paramMap.put("key", "2bff89fa33f84cb7b049d41cfced6e87");
            String s = HttpUtil.get("https://restapi.amap.com/v3/geocode/geo", paramMap);
            JSONObject jsonObject = JSONUtil.parseObj(s);
            String geocodes = jsonObject.getStr("geocodes");


            JSONArray objects = JSONUtil.parseArray(geocodes);
            JSONObject jsonObject1 = objects.getJSONObject(0);

            String location = jsonObject1.getStr("location");
            String[] split = location.split(",");
            customerReport.setX(split[0]);
            customerReport.setY(split[1]);
            HashMap<String, Object> paramMap2 = new HashMap<>();

            paramMap2.put("address", customerReport.getAddress());
            paramMap2.put("key", "2bff89fa33f84cb7b049d41cfced6e87");
            String s2 = HttpUtil.get("https://restapi.amap.com/v3/geocode/geo", paramMap2);
            JSONObject jsonObject2 = JSONUtil.parseObj(s2);
            String geocodes2 = jsonObject2.getStr("geocodes");


            JSONArray objects2 = JSONUtil.parseArray(geocodes2);
            JSONObject jsonObject12 = objects2.getJSONObject(0);

            String location2 = jsonObject12.getStr("location");
            String[] split2 = location2.split(",");
            customerReport.setXx(split2[0]);
            customerReport.setYy(split2[1]);
        }catch (Exception e){
            return customerReport;
        }
        return customerReport;
    }

}
